/**
 * 新增工程提报
 * Created by douxc on 2015/4/21.
 */
define(function (require, exports, module) {
  'use strict';
  module.exports = function (app) {
    app.register.controller('ProjectAddCtrl', ['$scope', '$routeParams', '$location', 'MHService',
      function ($scope, $routeParams, $location, MHService) {
        $scope.projectTitle = "水泥平台";
        MHService.globalData(true, {key: 'modeid', value: $routeParams['flag']});
        var url = MHService.URL.project_add
          + '?gardenid=' + MHService.globalData(false, {key: 'projectId'})
          + '&procedureid=' + MHService.globalData(false, {key: 'procedureid'})
          + '&modeid=' + $routeParams['flag'];
        MHService.getReq({url: url},
          function (data) {
            var datas = data['datas'],//获取的数据
              _formDatas = [];//代填的表单数据
            for (var index in datas) {
              var _data = datas[index];
              var _item = {
                id: _data.id,//计划成本id
                classid: _data.material.classid,//材料类型
                name: _data.material.name,//材料名称
                unit: _data.material.unit,//材料单位
                price: _data.price,//材料价格
                materialid: _data.materialid,//材料编号
                spec: _data.material.spec,//材料规格
                account: _data.account//计划数量
              };
              _formDatas.push(_item);
            }
            $scope.materials = angular.copy(_formDatas);
          });
          /**
           * 删除模块
           * @param selected
           */
          $scope.delmode=function(selected){
              var id=MHService.globalData(false, {key: 'modeid'});
              MHService.postReq({url: MHService.URL.del_tempMode, _req: {modeid:id}}, function (data) {
                  if (data['success']) {
                      //成功
                      MHService.Toast('删除成功');
                      history.go(-1);
                  }
              });
          }
        /**
         * 提交的表单数据
         * @param data
         */
        $scope.submit = function (data) {
          MHService.globalData(true, {key: 'materialSubmitData', value: data});
          $location.path('/projectSettle').replace();
        }
      }]);
  };
});
